
Page({
  data: {
    value: '',
    show: false,
    Provinces: [], // 选择框存放地址
    cityInfo: {
      name: "",
      id: ""
    },
    area: {
      name: "",
      id: ""
    },
    provincesInfo: {
      name: '',
      id: ""
    },
    // 接收个人信息的
    personal: {
      name: "",
      tel: "",
      address: ""
    },
    name: "",
    tel: "",
    address: "",
    lyx: []
  },
  onLoad: function (options) { },
  onConfirm(event) {
    // console.log(event);
    //城市
    if (!this.data.provincesInfo.name) {
      wx.request({
        url: 'https://api.it120.cc//common/region/v2/child',
        data: {
          pid: event.detail.value.id
        },
        method: 'GET',
        success: res => {
          this.setData({
            Provinces: res.data.data,
            provincesInfo: {
              id: event.detail.value.id,
              name: event.detail.value.name
            },
            show: false
          })
          // console.log(this.data.provincesInfo.id);
        }
      })
    } else if (!this.data.cityInfo.name) {
      // //县及
      wx.request({
        url: 'https://api.it120.cc//common/region/v2/districts',
        method: 'GET',
        success: res => {
          this.setData({
            Provinces: res.data.data.filter((el) => el.pid == event.detail.value.id),
            cityInfo: {
              id: event.detail.value.id,
              name: event.detail.value.name
            },
            show: false
          })
        }
      })

    } else {
      this.setData({
        area: {
          name: event.detail.value.name,
          id: event.detail.value.id
        },
        show: false
      })
    }
  },
  onCancel() {
    // Toast('取消');
    this.setData({
      show: false
    })
  },
  //保存个人信息
  preserve() {
    this.setData({
      personal: {
        name: this.data.name,
        tel: this.data.tel,
        address: this.data.address
      },
    })
    let data = {
      address: this.data.personal.address,
      cityId: this.data.cityInfo.id,
      linkMan: this.data.personal.name,
      mobile: this.data.personal.tel,
      provinceId: this.data.provincesInfo.id,
      token: wx.getStorageSync('token')
    }
    wx.request({
      url: 'https://api.it120.cc/zbt/user/shipping-address/add',
      method: 'POST',
      data:data,
      success: res => {
        console.log(res);
        
          // wx.navigateTo({
          //   url: '/pages/Myfulldetails/Receivingaddress/Receivingaddress',
          // })
        
      }
    })
  },
  onChange1(event) {
    // // event.detail 为当前输入的值
    // console.log(event.detail);
    if (!this.data.name) {
      this.setData({
        name: event.detail
      })
    } else if (!this.data.tel) {
      this.setData({
        tel: event.detail
      })
    } else if (!this.data.address) {
      this.setData({
        address: event.detail,
      })

    }
  },
  //省级
  click() {
    this.setData({
      show: true,
    })
    //省份信息
    wx.request({
      url: 'https://api.it120.cc/common/region/v2/province',
      method: 'GET',
      success: res => {
        // console.log(res.data.data);
        this.setData({
          Provinces: res.data.data
        })
      }
    })
    //城市
    // wx.request({
    //     url: 'https://api.it120.cc//common/region/v2/city',
    //     method: 'GET',
    //     success: res => {
    //         console.log(res.data.data);
    //     }
    // })





    // //区及
    // wx.request({
    //     url: 'https://api.it120.cc//common/region/v2/districts',
    //     method: 'GET',
    //     success: res => {
    //         console.log(res.data.data);
    //     }
    // })

  },
  //市级
  cityCk(event) {

    this.setData({
      show: true
    })
    // wx.request({
    //     url: 'https://api.it120.cc//common/region/v2/child',
    //     data: {
    //         pid: this.data.provincesInfo.id
    //     },
    //     method: 'GET',
    //     success: res => {
    //         console.log(res);
    //         // this.setData({
    //         //     Provinces: res.data.data,
    //         //     // provincesInfo: {
    //         //     //     id: this.data.provincesInfo.id,
    //         //     //     name: this.data.provincesInfo.name
    //         //     // },
    //         //     // show: false
    //         // })
    //     }
    // })
  },
  //区县
  areaCk(event) {
    this.setData({
      show: true
    })
  },

})